package com.woniu.car.controller;

import com.woniu.car.common.JWTUtil;
import com.woniu.car.common.ResponseEntity;
import com.woniu.car.dto.CommentInsertDto;
import com.woniu.car.dto.CommentQueryDto;
import com.woniu.car.dto.ResponseCodeDto;
import com.woniu.car.exception.ServiceSException;
import com.woniu.car.param.*;
import com.woniu.car.service.TServiceCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ServerCommentController
 * @Description TODO
 * @Author 李磊
 * @Version 1.0
 **/
@RestController
@RequestMapping("/comment")
@Api(tags = "服务评论模块")
@Slf4j
public class CommentController {

    @Resource
    private TServiceCommentService tServiceCommentService;

    /**
    *@Author 李磊
    *@Description 新增商品评论
    *@Param [commentInsertParam, bindingResult]
    *@return com.woniu.car.common.ResponseEntity
    **/
    @PostMapping("/insert")
    @ApiOperation("新增评论")
    public ResponseEntity insertComment(@Validated CommentInsertParam commentInsertParam,@RequestHeader("ID") Integer id){


        CommentInsertDto insert = tServiceCommentService.insert(commentInsertParam, id);

        return new ResponseEntity(ResponseCodeDto.SUCCESS.getCode(),
                ResponseCodeDto.SUCCESS.getMessage(),
                insert);
    }

    /**
    *@Author 李磊
    *@Description 查询评论信息
    *@Param [commentQueryParam]
    *@return com.woniu.car.common.ResponseEntity
    **/
    @GetMapping("/query")
    @ApiOperation("查询评论")
    public ResponseEntity queryComment(@Validated CommentQueryParam commentQueryParam) throws Exception{

        List<CommentQueryDto> commentQueryDtos = tServiceCommentService.queryComment(commentQueryParam);

        return new ResponseEntity(ResponseCodeDto.SUCCESS.getCode(),
                ResponseCodeDto.SUCCESS.getMessage(),
                commentQueryDtos);
    }

    /**
    *@Author 李磊
    *@Description 用户追评
    *@Param [upadateCommentByUserParam, bindingResult]
    *@return com.woniu.car.common.ResponseEntity
    **/
    @PutMapping("/updateByUser")
    @ApiOperation("用户追评")
    public ResponseEntity updateCommentByUser(@Validated UpadateCommentByUserParam upadateCommentByUserParam){

        CommentQueryDto commentQueryDto = tServiceCommentService.updateCommentByUser(upadateCommentByUserParam);

        return new ResponseEntity(ResponseCodeDto.SUCCESS.getCode(),
                ResponseCodeDto.SUCCESS.getMessage(),
                commentQueryDto);
    }

    /**
    *@Author 李磊
    *@Description 商家回复
    *@Param [updateCommentByShopParam]
    *@return com.woniu.car.common.ResponseEntity
    **/
    @PutMapping("/updateByShop")
    @ApiOperation("商家回复")
    public ResponseEntity updateCommentByShop(@Validated UpdateCommentByShopParam updateCommentByShopParam) throws ServiceSException {

        CommentQueryDto commentQueryDto = tServiceCommentService.updateByShop(updateCommentByShopParam);

        return new ResponseEntity(ResponseCodeDto.SUCCESS.getCode(),
                ResponseCodeDto.SUCCESS.getMessage(),
                commentQueryDto);
    }

    /**
    *@Author 李磊
    *@Description 商家追评回复
    *@Param [updateCommentByShopTParam]
    *@return com.woniu.car.common.ResponseEntity
    **/
    @PutMapping("/updateByShopT")
    @ApiOperation("商家追评回复")
    public ResponseEntity updateCommentByShopT(@Validated UpdateCommentByShopTParam updateCommentByShopTParam) throws ServiceSException {

        CommentQueryDto commentQueryDto = tServiceCommentService.updateByShopT(updateCommentByShopTParam);

        return new ResponseEntity(ResponseCodeDto.SUCCESS.getCode(),
                ResponseCodeDto.SUCCESS.getMessage(),
                commentQueryDto);
    }


    /**
    *@Author 李磊
    *@Description 用户删除评论
    *@Param [updateCommentParam]
    *@return com.woniu.car.common.ResponseEntity
    **/
    @PutMapping("/updateComment")
    @ApiOperation("用户删除评论")
    public ResponseEntity updateComment(Integer commentId,@RequestHeader("id") Integer id) throws ServiceSException {

        UpdateCommentParam updateCommentParam = new UpdateCommentParam();
        updateCommentParam.setCommentId(commentId);
        updateCommentParam.setUserId(id);
        CommentQueryDto commentQueryDto = tServiceCommentService.updateComment(updateCommentParam);

        return new ResponseEntity(ResponseCodeDto.SUCCESS.getCode(),
                ResponseCodeDto.SUCCESS.getMessage(),
                commentQueryDto);
    }


}
